using Nekonya.Components;
using Nekonya.Const;
using TinaX;
using TinaX.UIKit;
using TinaX.XComponent;
using UniRx;
using UnityEngine;
using UnityEngine.UI;

namespace Nekonya.UI
{
    public class GameMainScreen : XUIBehaviour
    {

        [Binding("txt_Watchable_Title")]
        public Text Txt_Watchable_Title { get; set; }

        [Binding("txt_Watchable_Desc")]
        public Text Txt_Watchable_Desc { get; set; }

        [Inject]
        public IUIKit UIKit { get; set; }

        public override void Awake()
        {
            Txt_Watchable_Title.text = string.Empty;
            Txt_Watchable_Desc.text = string.Empty;



            XEvent.Register(EventConst.OnPlayerWatch, watcher =>
            {
                if(watcher is InteractiveObservationComponent)
                {
                    var ioc = (InteractiveObservationComponent)watcher;
                    Txt_Watchable_Title.text = ioc.Title;
                    Txt_Watchable_Desc.text = ioc.Description;
                }
            });

            XEvent.Register(EventConst.PlayerLostWatch, _ =>
            {
                Txt_Watchable_Title.text = string.Empty;
                Txt_Watchable_Desc.text = string.Empty;
            });

            Observable.EveryUpdate()
                .Where(_ => Input.GetKeyDown(KeyCode.B))
                .Subscribe(_ =>
                {
                    Debug.Log("B键被按下，打开背包UI");
                    UIKit.OpenUIAsync("bagScreen.simple", new BagScreenSimple(), new OpenUIParam { UseMask = true, }, (ui, err) => { });
                })
                .AddTo(this.gameObject);

        }


    }
}
